import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import { Loading } from 'element-ui';
//引入icon
import "./assets/font/iconfont.css"
import Axios from 'axios' //引入axios

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';

Vue.use(ElementUI);
Vue.config.productionTip = false
    //axios拦截器
    //发送请求之前触发
axios.interceptors.request.use(config => {
        console.log("请求之前", config)
        config.headers.Authorization = sessionStorage.getItem("token")
            //等待
        Loading.service();
        return config
    })
    //服务器相应之后触发
axios.interceptors.response.use(config => {
    console.log("请求之后", config);
    Loading.service().close();
    //只有token失效才会跳转登录页
    if (config.data.meta.status == 400 || config.data.meta.status == 401) {
        router.push('/login')
    }
    return config;
})



Vue.prototype.axios = Axios;
Axios.defaults.baseURL = "http://121.41.51.231:5000/api/private/v1/"


new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')